package com.example.controller;


import com.example.service.ProductService;
import com.example.utils.JsonData;
import com.example.vo.ProductVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author yinxin
 * @since 2022-06-13
 */
@RestController
@RequestMapping("/api/product/v1")
public class ProductController {

    @Autowired
    ProductService productService;

    /**
     * 查询商品列表
     * @return
     */
    @GetMapping("/list")
    public List<ProductVO> getInfo(){
        return productService.list();
    }

    /**
     * 查看商品详情
     * @param id
     * @return
     */
    @GetMapping("/detail/{product_id}")
    public JsonData findDetailById(@PathVariable("product_id") Long id){
        ProductVO productVO = productService.findDetailById(id);
        return JsonData.buildSuccess(productVO);
    }
}

